<?php

class ZFWork_Boxes_Box {

	private $_boxAlternate = false;
	private $_boxId = 'box';
	private $_boxLabel;
	private $_boxType = '100';
	private $_buttonsHeader = array();
	//private $_forms = array();
	//private $_id;
	private $_itens = array();
	//private $_parts = array();
	private $_showTabs = false;
	private $_tabs = array();

	public function __construct($label, $id=null) {
		$this->_boxLabel = $label;

		if (empty($id)) {
			$id = 'box_' . preg_replace('#[^a-z0-9]#i', '', $label);
		}
		$this->_boxId = $id;
	}
	
	public function addButtonHeader($label, $id, $link) {
		$this->_buttonsHeader[] = array(
			'id' => $this->_boxId . '_' . $id,
			'label' => $label,
			'link' => $link,
		);
	}

	public function addForm(Zend_Form $form) {
		$this->addItem($form->getId(), $form);
	}
	
	public function addGrid(Bvb_Grid $grid) {
		$this->addItem($grid->getNameGrid(), $grid);
	}
	
	protected function addItem($key, $value) {
		$this->_itens[$key] = $value;
	}

	public function addPart($partName, $partValues=array()) {
		$this->addItem($partName, array(
			'name' => $partName,
			'type' => 'part',
			'values' => $partValues,
		));
	}

	public function addTab($label, $id=null, $active=false) {
		if (empty($id))
			$id = $this->getBoxId () . '_lb_' . $label;

		if (!$label instanceof ZFWork_Boxes_Tab) {
			$label = new ZFWork_Boxes_Tab($label, $id);
			$label->isActive($active);
		}

		$this->_showTabs = true;
		$this->_tabs[$id] = $label;
	}

	public function getBoxAlternate() {
		return $this->_boxAlternate;
	}

	public function getBoxId() {
		return $this->_boxId;
	}

	public function getBoxLabel() {
		return $this->_boxLabel;
	}

	public function getBoxType() {
		return $this->_boxType;
	}
	
	public function getButtonsHeader() {
		return $this->_buttonsHeader;
	}

	public function getForms() {
		//return $this->_forms;
		return $this->_itens;
	}
	
	public function getItens() {
		return $this->_itens;
	}
	
	public function getParts() {
		//return $this->_parts;
		return $this->_itens;
	}

	public function getShowTabs() {
		return $this->_showTabs;
	}

	public function getTabs() {
		return $this->_tabs;
	}
	
	public function setBoxAlternate($alternate=true) {
		$this->_boxAlternate = $alternate;
	}
	
	public function setBoxType($type) {
		switch($type) {
			case 100:
			case 75:
			case 50:
			case 25:
				$this->_boxType = $type;
		}
	}

}